<?php
// Copyright (c) 2012 Mirza Adipradhana
// @ref EVOKNOW, Inc.
// @modified by Mirza Adipradhana
/*
* Sentralisasi keseluruhan Error Message
* Multi-language support
*/


//Menyatakan apakah DEBUGGER telah terLOAD
define("DEBUGGER_LOADED", true);

class Debugger {
	private $mTextColor = CORE_DEBUG_TEXT_COLOR;
	private $mColor;
	private $mPrefix;
	private $mLine;
	private $mBufferStr;
	private $mBuffer;
	private $mBannerPrinted;
	
	public function __construct($pParams = null) {
		$this->mColor = $pParams['color'];
		$this->mPrefix = $pParams['prefix'];
		$this->mLine=0;
		$this->mBufferStr=0;
		$this->mBuffer= $pParams['buffer'];
		$this->mBannerPrinted= false;
    }
	
	public function PrintBanner() {
		$tOut= '';
		if($this->mBannerPrinted ==  true)
			return 0;
			
		$tOut.= '<br>
				<div style="color:'.$this->mTextColor.'">
				<b>Debug started for '.$this->mPrefix.'</b>	
				</div>
				<hr />';
				
		if($this->mBuffer == true){
			$this->mBufferStr .= $tOut;
		}
		else {
			echo $tOut;
			$this->mBannerPrinted = true;
		}
		return 1;
	}

	public function Write($pMsg) {
		$tOut= '';
		$tOut= sprintf("<div style='color:%s'%03d &nbsp;</div>
						<div style='color:%s'%s</div><br>\n",
						$this->mTextColor, $this->mLine, $this->mColor, $pMsg
					   );
					   
		if($this->mBuffer == true){
			$this->mBufferStr .= $tOut;
		}
		else {
			echo $tOut;
		}
	}
	
	public function DebugArray($pHash = null) {
		while(list($tKey, $tValue) = each($pHash) ){
			$this->Write("$tKey = $tValue");
		}
	}
	
	public function SetBuffer(){
		$this->mBuffer = true;
	}
	
	public function ResetBuffer(){
		$this->mBuffer = false;
		$this->mBufferStr = null;
	}
	
	public function FlushBuffer(){
		$this->mBuffer = false;
		$this->PrintBanner();
		echo $this->mBufferStr;
	}
}


?>